﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using HRProject.Code.DAO;
using HRProject.Code.Common;
using HRProject.Code.DTO;
using System.IO;
using System.Text;

namespace HRProject.Asset
{
    public partial class EditAsset : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (fulIcon.HasFile)
            {
                try
                {
                    string ext = fulIcon.PostedFile.FileName.Substring(fulIcon.PostedFile.FileName.LastIndexOf('.'));
                    string serverFolder = "/image/temp/" + Util.GetSessionID(Session) + "/asset/";
                    string folder = MapPath(serverFolder);
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }
                    string iconUrl = folder + DateTime.Now.ToString("yyyyMMdd-HHmmss") + ext;
                    string serverIconUrl = serverFolder + DateTime.Now.ToString("yyyyMMdd-HHmmss") + ext;
                    fulIcon.PostedFile.SaveAs(iconUrl);
                    hdfImageUrl.Value = serverIconUrl;
                    imgAsset.ImageUrl = serverIconUrl;
                }
                catch (Exception ex)
                {
                    lblError.Text = "ERROR: " + ex.Message.ToString();
                }
            }
            else
            {
                lblError.Text = ContentProvider.GetMessage("InvalidFile");
            }
        }
    }
}
